package com.example.styconsumer.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.styinterface.interfaces.IElasticSearchService;
import com.example.styinterface.utils.R;
import com.example.stymodel.model.Apple;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author wcq
 */
@RestController
@RequestMapping("/es")
public class ElasticSearchController {
    @Reference()
    IElasticSearchService elasticSearchService;
    //和apple先用同一个表测试
    @PostMapping("/insertDocument/{index}")
    public R esInsertDocument(@PathVariable String index,@RequestBody Apple apple) throws IOException {
        return elasticSearchService.insertDocument(index,apple);

    }
    @DeleteMapping("/deleteDocument/{index}/{id}")
    public R esDeleteDocument(@PathVariable String index,@PathVariable Integer id) throws IOException {
        return elasticSearchService.deleteDocument(index,id);

    }

    @GetMapping("/selectDocument/{index}/{price}")
    public R esSelectDocumentByPrice(@PathVariable String index,@PathVariable String price) throws IOException {
        return elasticSearchService.selectDocument(index,price);
    }
    @PostMapping("/addIndex/{index}")
    public R esAddIndex(@PathVariable String index) throws IOException {
        return elasticSearchService.addIndex(index);

    }
    @DeleteMapping("/deleteIndex/{index}")
    public R esDeleteIndex(@PathVariable String index) throws IOException {
        return elasticSearchService.deleteIndex(index);

    }

}
